package com.umakr.demo.controller;

import com.umakr.demo.model.Nianji;
import com.umakr.demo.service.NianjiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by yangliu on 2017/8/18.
 */
@Controller
@RequestMapping("/NianjiController")
public class NianjiController {

    @Autowired
    NianjiService nianjiService;
    //显示年级的页面
    @RequestMapping("/showNianji")
    public String showNianji(){
        return "StudentManage/nianji";
    }

    //   显示年级的数据
    @RequestMapping("/nianjiData")
    @ResponseBody
    public List nianjiData(){
        List<Nianji> list = nianjiService.showAll();
        System.out.println(list);
        return list;
    }

    //保存年级数据
    @RequestMapping("/saveNianji")
    @ResponseBody
    public List saveNianji(Long nid,String nname){
        Nianji nianji = new Nianji(nid,nname);
        nianjiService.saveNianji(nianji);
        List<Nianji> list = nianjiService.showAll();
        System.out.println(list);
        return list;
    }

//    更新年级数据
    @RequestMapping("/updataNianji")
    @ResponseBody
    public List updataNanji(Long nid,String nname){
        Nianji nianji = new Nianji(nid,nname);
        nianjiService.updataNianji(nianji);
        List<Nianji> list = nianjiService.showAll();
        return list;
    }

    //删除年级
    @RequestMapping("/deleteNianji")
    @ResponseBody
    public List deleteNianji(Long nid,String nname){
        Nianji nianji = new Nianji(nid, nname);
        nianjiService.deleteNianji(nianji);
        List<Nianji> list = nianjiService.showAll();
        return list;
    }
}
